<template>
    <!-- 名称弹窗 -->
    <div class="front">
        <el-input v-model="searchDepartText" placeholder="输入关键字" style="margin: 10px 0!important"></el-input>
        <div class="tree">
			<el-tree :data="objectsData" :accordion="true" :expand-on-click-node="false" :props="defaultProps" :filter-node-method="filterNode" ref="tree" @node-click="getCurrentTreeData" :default-expand-all="true" :highlight-current="true"></el-tree>
		</div>
    </div>
</template>
<script>
/**
 * Author: 赵巧芬
 * Date: 2019-3
 * Description: 选择客户资料名称组件
 * accountProjectStore
*/
    export default {
        data() {
            return {
                searchDepartText: '',
                objectsData:this.$store.state.initializeStore.customerData,
                defaultProps: {
                    label: 'name',
                    children: 'clients'
                },
            }
        },
        watch: {
            searchDepartText(val){
                this.$refs.tree.filter(val);
            }
        },
        methods: {
            filterNode(value, data) {               //名称选择里面的搜索框
                if (!value) return true;
                return data.name.indexOf(value) !== -1;
            },
            getCurrentTreeData(row) {               //单击
                if(row['belongToSeries']){
                    this.$message({message: '请选择具体的往来对象！', type: 'warning'});
                }else{
                    this.$store.commit('initializeStore/updateObject', row);
                    this.close();
                }
            },
            close() {                               //关闭新增弹窗
                let index = parent.layer.getFrameIndex(window.name);    //先得到当前iframe层的索引
                parent.layer.close(index);
            },
        },
        created() {
            //获取客户资料下的所有数据
            this.$store.dispatch('initializeStore/getCustomerData', this.$url + 'client/findAccountItemByName?name=客户大类&systemId=' + this.$store.state.systemId);
        }
    }
</script>